package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;

public interface CheckGroupMapper extends BaseMapper<CheckGroup> {

    @Insert("insert  into t_checkgroup_checkitem values(#{gid},#{checkitemId})")
    void addCheckGroupIdAndCheckItemId(@Param("gid") int gid, @Param("checkitemId") Integer checkitemId);

    @Select("select  CHECKITEM_ID from  t_checkgroup_checkitem where CHECKGROUP_ID=#{id}")
    int[] findCheckItemIdsByGroupId(@Param("id") int id);

   @Delete("delete from t_checkgroup_checkitem where CHECKGROUP_ID=#{id}")
    void deleteCheckItemIdsByGroupId(@Param("id") Integer id);

   @Select("SELECT  tc.name " +
           "FROM t_checkitem tc, t_checkgroup_checkitem tcc " +
           "WHERE tc.id = tcc.CHECKITEM_ID " +
           "and tcc.CHECKGROUP_ID = #{id}")
    List<CheckItem> findCheckItemByGid(@Param("id") Integer id);
}
